/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.ruby_string.delayed;

import moved.org.objectweb.asm.MethodVisitor;

public class ParameterAnnotation extends AbstractMethodInstruction {
	private final String name;
	private final boolean visible;
	private final int parameter;
	private final DelayedAnnotationMutator delayedAnnotationMutator;

	public ParameterAnnotation(int parameter, String name, boolean visible,
		DelayedAnnotationMutator delayedAnnotationMutator) {

		this.parameter = parameter;
		this.name = name;
		this.visible = visible;
		this.delayedAnnotationMutator = delayedAnnotationMutator;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// MethodInstruction Methods
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	public void accept(MethodVisitor methodVisitor) {
		delayedAnnotationMutator.accept(
			methodVisitor.visitParameterAnnotation(parameter, name, visible));
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Object Methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	@Override
	public boolean equals(Object object) {
		if (object == null || !(object.getClass().equals(getClass()))) {
			return false;
		}
		
		ParameterAnnotation other = (ParameterAnnotation) object;
		
		return parameter == other.parameter &&
			name.equals(other.name) &&
			visible == other.visible;
	}
	
	@Override
	public int hashCode() {
		return getClass().hashCode();
	}
	
	@Override
	public String toString() {
		return "VisibleAnnotation: " + name + ", " + visible;
	}
}
